
from django.contrib.auth import get_user_model
from factory import Faker, post_generation
from factory.django import DjangoModelFactory
import factory
from backend.cews.models import Parts, PartsReplacement, RepairOrder, RepairOrderEDoc, RepairOrderPart, RepairOrderPartReplacement, StockItem, StockItemEDoc, StockItemRelation, StockItemReplacement, StockItemTask,Task

class RepairOrderReplacementFactory(DjangoModelFactory):
    class Meta:
        model = RepairOrderPartReplacement


class StockItemReplacementFactory(DjangoModelFactory):
    class Meta:
        model = StockItemReplacement
    component = factory.sequence(lambda n: 'component %d' % n)
    period = Faker("random_int",min=1,max=5)
        
class PartsReplacementFactory(DjangoModelFactory):
    class Meta:
        model = PartsReplacement

class TaskFactory(DjangoModelFactory):
    class Meta:
        model = Task

class StockItemEDocFactory(DjangoModelFactory):
    doc_name = Faker("name")
    class Meta:
        model = StockItemEDoc
        
class RepairOrderEDocFactory(DjangoModelFactory):
    class Meta:
        model = RepairOrderEDoc


class StockItemRelationFactory(DjangoModelFactory):
    class Meta:
        model = StockItemRelation

class StockItemTaskFactory(DjangoModelFactory):
    name = Faker("name")
    class Meta:
        model = StockItemTask

class PartsFactory(DjangoModelFactory):
    serial_no = factory.sequence(lambda n: 'SN%03d' % n)
    
    class Meta:
        model = Parts

class StockItemFactory(DjangoModelFactory):

    class Meta:
        model = StockItem
        django_get_or_create = ["stock_code"]
    
    stock_code = factory.Sequence(lambda n: '%010d' % n)
    car = '239'
    sw_ver = '1.1.0'
    hw_ver = '2.2.0'
    system = 'system'
    description = 'description'
    lv1 = 'lv1'
    lv2 = 'lv2'
    lv3 = 'lv3'
    lv4 = 'lv4'
    lv5 = 'lv5'
    lv6 = ''
    date_code = '2023/06'

class RepairOrderFactory(DjangoModelFactory):

    class Meta:
        model = RepairOrder

class RepairOrderPartFactory(DjangoModelFactory):

    class Meta:
        model = RepairOrderPart